/**
 * Created by clown on 2016/1/31.
 */


(function($){

	var $pagination = $('<div></div>');
	$pagination.addClass("m-pagination").attr("id","page");
	$(".person-content").append($("#page"));
	$("#page").pagination({
		pageSize: 10,
		total: 0,
		pageBtnCount: 6,
		showFirstLastBtn:false,
		prevBtnText:"<",
		nextBtnText:">"
	});
	$("#page").on("pageClicked", function (event, data) {
		render(data);
	});

	var informationHtml = $("#information-template").html();
	var informationTpl= Handlebars.compile(informationHtml);
	var render = function(opts) {
		$.get("/lt/viewpoint/list", _.extend({}, opts),function(data){
			if(!data.result){
				var htmlStr = "<div class='info-list-img'><img src="+data.headLine.logoUrl+"><div class='info-list-img-bg'><div class='info-list-img-title'>"+data.headLine.title+"</div></div></div>";
				$(".info-list-content-title").html(htmlStr);
				$(".info-list-content-detail").html(informationTpl(data));
				if(data.total) {
					$("#page").pagination('setPageSize', data.total);
				}
			}
		});
	};
	render();

	var infoHotHtml = $("#infoHot-template").html();
	var infoHotTpl= Handlebars.compile(infoHotHtml);
	var infoHotFun = function(opts) {
		$.get("/lt/viewpoint/hotest", _.extend({}, opts),function(data){
			if(!data.result){
				$(".info-hot-content").html(infoHotTpl(data));
			}
		});
	};
	infoHotFun();
})(jQuery);